package com.qmx.qmxapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.qmx.qmxapp.R;
import com.qmx.qmxapp.base.BaseActivity;
import com.qmx.qmxapp.callback.DialogCallback;
import com.qmx.qmxapp.constant.AppConstant;
import com.qmx.qmxapp.constant.ComParamContact;
import com.qmx.qmxapp.utils.Validator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserLoginSetActivity extends BaseActivity {

    private TextView tip_content;
    @BindView(R.id.next)
    TextView next;

    @BindView(R.id.edit_user_name)
    EditText edit_user_name;
    @BindView(R.id.edit_password)
    EditText edit_password;
    @BindView(R.id.edit_email)
    EditText edit_email;

    private String mobile = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_login_set);
        ButterKnife.bind(this);
        tip_content = findViewById(R.id.tip_content);
        tip_content.setText("设置个人信息");

        mobile = this.getIntent().getStringExtra("mobile");


    }

    @OnClick(R.id.next)
    public void onclick(View view) {
        Intent i = new Intent();
        switch (view.getId()) {
            case R.id.next:
                if (TextUtils.isEmpty(getName()) || TextUtils.isEmpty(getEmail()) || TextUtils.isEmpty(getPassword())) {
                    return;
                }
                doRegister();
                i.setClass(this, PersonMeetingActivity.class);
                break;
        }
        startActivity(i);
    }


    public String getName() {
        String user_name = edit_user_name.getText().toString();
        if (TextUtils.isEmpty(user_name)) {
            showToast("请输入姓名");
        }
        return user_name;
    }

    public String getEmail() {
        String email = edit_email.getText().toString();
        if (TextUtils.isEmpty(email) || !Validator.isEmail(email)) {
            showToast("请输入邮箱");
        }
        return email;
    }

    public String getPassword() {
        String password = edit_password.getText().toString();
        if (TextUtils.isEmpty(password) || !Validator.isPassword(password)) {
            showToast("请输入密码");
        }
        return password;
    }

    public void doRegister() {
        OkGo.<String>post(AppConstant.Url + ComParamContact.Register.PATH)
                .params(ComParamContact.Register.APP_TYPE, "1")
                .params(ComParamContact.Register.AREA_CODE, "+86")
                .params(ComParamContact.Register.MOBILE, mobile)
                .params(ComParamContact.Register.EMAIL, getEmail())
                .params(ComParamContact.Register.NAME, getName())
                .params(ComParamContact.Register.PASSWORD, getPassword())
                .execute(new DialogCallback<String>(this) {

                    @Override
                    public void onSuccess(Response<String> response) {
                        showToast(response.body());
//                            handleResponse(response);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        showToast("接口有问题");
//                            handleError(response);
                    }
                });
    }
}
